﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="../res/css/amazeui.basic.css" rel="stylesheet" />
    <link href="../res/css/goodslist.css" rel="stylesheet" />
    <script src="../libs/amazeui.basic.js"></script>
    <script src="../libs/jquery-1.9.1.js"></script>
    <script>
        //decode json string to the json object
        function decodeJson(json) {
            return (new Function('return '+json))();
        }

        //加载商品数据
        function loadGoods(json){
            $('#div_button').css('display','none');
            var jsonlist = decodeJson(json);
            if(jsonlist!=null && jsonlist.length>0){
                for(var i=0;i<jsonlist.length;i++){
                    try{
                        var goods = jsonlist[i];
                        var list_row = '<tr>'
                            + '<td>' + goods['mc']+ '</td>'
                            + '<td><input id="et_js_'+i+'" type="text" class="am-form-field am-radius"/></td>'
                            + '<td><input id="et_ss_'+i+'" type="text" class="am-form-field am-radius"/></td>'
                            + '</tr>';
                        $('#list').append(list_row);
                    }catch(e){
                        alert(e.message);
                    }
                }
            }
        }

        //清空商品数据
        function clearGoods(){
            $('#list').html('');
        }

        //获取列表所有输入
        function getAllInput(){
            try{
                var tbl = document.getElementById('tbl_goods');
                var rleng = tbl.rows.length;//获取列表长度
                var goodslst = [];
                var i = 0;
                for(var i=0;i<rleng;i++){
                    var js = $('#et_js_'+i).val();
                    var ss = $('#et_ss_'+i).val();
                    if(!isNaN(js) && !isNaN(ss)){
                        goodslst[i++] = {"js":js,"ss":ss};
                    }else if(!isNaN(js) && ss == ''){
                        goodslst[i++] = {"js":js,"ss":ss};
                    }else if(js == '' && !isNaN(ss)){
                        goodslst[i++] = {"js":js,"ss":ss};
                    }
                }
                alert(JSON.stringify(goodslst));
            }catch(e){
                alert(e.message);
            }
        }

    </script>
</head>
    <body>
        <table id="tbl_goods" class="am-table am-table-bd am-table-bdrs">
            <thead>
                <tr>
                    <th>商品名称</th>
                    <th>件数</th>
                    <th>散数</th>
                </tr>
            </thead>
            <tbody id="list">
            </tbody>
        </table>
    </body>
</html>
